//
//  NDEndpoint.swift
//  NyamanDana
//
//  Created by 李永彬 on 2025/10/24.
//

import UIKit
import Alamofire

// MARK: - 端点协议
protocol NDEndpoint {
    var domain: NDAPIDomain { get }
    var path: String { get }
    var method: HTTPMethod { get }
    var parameters: [String: Any]? { get }
    var contentType: NDContentType { get }
    var headers: HTTPHeaders? { get }
}

// MARK: - 基础端点实现
struct NDBaseEndpoint: NDEndpoint {
    let domain: NDAPIDomain
    let path: String
    let method: HTTPMethod
    let parameters: [String: Any]?
    let contentType: NDContentType
    let headers: HTTPHeaders?
    
    init(
        domain: NDAPIDomain,
        path: String,
        method: HTTPMethod = .get,
        parameters: [String: Any]? = nil,
        contentType: NDContentType = .formUrlEncoded,
        headers: HTTPHeaders? = nil
    ) {
        self.domain = domain
        self.path = path
        self.method = method
        self.parameters = parameters
        self.contentType = contentType
        self.headers = headers
    }
}

// MARK: - 上传端点
struct NDUploadEndpoint: NDEndpoint {
    let domain: NDAPIDomain
    let path: String
    let method: HTTPMethod = .post
    let parameters: [String: Any]?
    let contentType: NDContentType = .multipartForm
    let headers: HTTPHeaders?
    
    let fileData: Data
    let fileName: String
    let mimeType: String
    let formDataName: String
    
    init(
        domain: NDAPIDomain,
        path: String,
        parameters: [String: Any]? = nil,
        headers: HTTPHeaders? = nil,
        fileData: Data,
        fileName: String,
        mimeType: String = "image/jpeg",
        formDataName: String = "sentiity"
    ) {
        self.domain = domain
        self.path = path
        self.parameters = parameters
        self.headers = headers
        self.fileData = fileData
        self.fileName = fileName
        self.mimeType = mimeType
        self.formDataName = formDataName
    }
}
